<template>
  <div class="container">
    <vxe-toolbar
      id="warehouseLocationId"
      :custom="{ storage: true }"
      export
      :refresh="{query: findList}"
    >
      <template v-slot:buttons>
        <div class="btnMargin btnMarginTop">
          <span>商品编码 <el-input class="inputWidth" placeholder="商品编码1,商品编码2,商品编码3" clearable v-model="listQuery.normalGoodCodes" /></span>&emsp;
          <el-button @click="commodityClick">商品查询</el-button>&emsp;&emsp;&emsp;
          <span>商品编码 <el-input class="inputWidth" placeholder="商品编码1,商品编码2,商品编码3" clearable v-model="listQuery.goodCodes" /></span>&emsp;
          <span>商品数量 <el-input class="inputWidth" placeholder="数量1,数量2,数量3" clearable v-model="listQuery.goodsNums" /></span>&emsp;
          <el-button @click="explosiveClick">爆品查询</el-button>
        </div>
        <queryCriteria :listQuery="listQuery" :optionList="{ options, orderData, typeList, carrierList, gmtCreatedRange }" @carrierChange="carrierChange" @changeGmtCreatedRange="changeDate" />
        <div class="btnMargin">
          <el-button @click="findList('good')">查询</el-button>
          <el-button v-bind:disabled="printFlag" @click="waveShowHide">生成波次</el-button>
          <el-button :disabled="printWaybillBtn" @click="printWaybill">打印运单</el-button>
          <el-button :disabled="printWaybillBtn" @click="cancelWaveClick">取消波次</el-button>
          <el-button :disabled="printWaybillBtn" @click="changeCarrier">更改承运商</el-button>
          <span class="ml20">停发区域 <el-cascader v-model="areaInfo" style="width: 16%" :options="areaOptions" :show-all-levels="false" collapse-tags :props="{ multiple: true, value: 'countyName', label: 'countyName', children: 'children' }" filterable clearable /></span>
          <span class="ml20">筛选区域 <el-cascader v-model="receiverDistricts" style="width: 16%" :options="areaOptions" :show-all-levels="false" collapse-tags :props="{ multiple: true, value: 'countyName', label: 'countyName', children: 'children' }" filterable clearable /></span>
          <!-- <el-button :disabled="disabled" @click="updateWaybill">更新运单信息</el-button> -->
        </div>
      </template>
    </vxe-toolbar>
      <!-- <el-button :disabled="printFlag && generatePicking" @click="generate">获取运单号</el-button> -->
    <vxe-table
      ref="xTable"
      border
      resizable
      :export-config='{type:"csv"}'
      stripe
      highlight-current-row
      show-footer
      highlight-hover-row
      row-id="id"
      :loading="loading"
      class="mytable-footer"
      height="640"
      align="center"
      :data="tableData"
      :edit-config="{ trigger: 'click', mode: 'row', showStatus: true }"
      :sort-config="{ remote: true }"
      @sort-change="sortField"
      @cell-click="copyText"
      @checkbox-all="checkboxChangeEvent"
      @checkbox-change="checkboxChangeEvent"
      :seq-config="{startIndex: listQuery.pageNum * listQuery.pageSize - listQuery.pageSize}"
    >
      <vxe-table-column type="seq" width="60"></vxe-table-column>
      <vxe-table-column type="checkbox" width="60"></vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="status"
          title="状态"
          min-width="150"
          sortable
          :formatter="({ cellValue }) => this.getEnumsOrDict('dict', 'orderStatus').get(String(cellValue))"
        />
        <template #header>
          <el-select v-model="listQuery.status" placeholder="请选择" clearable>
            <el-option
              v-for="item in getEnumsOrDict('enum', 'orderStatus')"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="sourceType"
          title="数据来源"
          min-width="150"
          sortable
          :formatter="formatterSource"
        />
        <template v-slot:header="{ column }">
          <el-select v-model="listQuery.sourceType" placeholder="请选择" clearable>
            <el-option
              v-for="item in sourceList"
              :key="item.code"
              :label="item.message"
              :value="item.code"
            ></el-option>
          </el-select>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="prepackaged"
          title="是否预打包"
          min-width="150"
          sortable
          :formatter="formatterPackaged"
        />
        <template v-slot:header="{ column }">
          <el-select v-model="listQuery.prepackaged" placeholder="请选择" clearable>
            <el-option
              v-for="item in prepackagedList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="warehouseName" title="仓库" min-width="150" />
        <template v-slot:header="{ column }">
          <el-select v-model="listQuery.warehouseCode" placeholder="请选择仓库 " style="width:100%" clearable>
            <el-option
              v-for="item in warehouseData"
              :key="item.code"
              :label="item.name"
              :value="item.code"
            />
          </el-select>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="shipmentName"
          title="入驻商"
          min-width="150"
          sortable
        />
        <template v-slot:header="{ column }">
          <el-select v-model="listQuery.shipmentName" clearable filterable placeholder="入驻商">
            <el-option
              v-for="item in options"
              :key="item.partyCode"
              :label="item.userName"
              :value="item.userName">
            </el-option>
          </el-select>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="shopNick"
          title="店铺"
          min-width="150"
          sortable
        />
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.shopNick" placeholder="店铺" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="wavePickingCode"
          title="波次号"
          min-width="150"
          sortable
        />
        <template v-slot:header="{ column }">
          <el-input
            v-model="listQuery.wavePickingCode"
            placeholder="波次号"
            clearable
          />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="code"
          title="订单号"
          min-width="150"
          sortable
        />
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.code" placeholder="订单号" clearable />
        </template>
      </vxe-table-column>
       <vxe-table-column>
        <vxe-table-column field="orderTag" title="订单标识" min-width="150" />
        <template v-slot:header="{ column }">
          <!-- goodsSortQuantity -->
          <el-select v-model="listQuery.orderTag" placeholder="请选择订单标识 " style="width:100%" clearable>
            <el-option
              v-for="item in orderData"
              :key="item.orderTag"
              :label="item.orderTag"
              :value="item.orderTag"
            />
          </el-select>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="sourceCode"
          title="来源单号"
          min-width="150"
          sortable
        />
        <template v-slot:header="{ column }">
          <el-input
            v-model="listQuery.sourceCode"
            placeholder="来源单号"
            clearable
          />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="isvCode"
          title="原始单号"
          min-width="150"
          sortable
        />
        <template v-slot:header="{ column }">
          <el-input
            v-model="listQuery.isvCode"
            placeholder="原始单号"
            clearable
          />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="type" title="单据类型" min-width="200" :formatter="formatterType" />
        <template v-slot:header="{ column }">
          <el-select v-model="listQuery.type" placeholder="请选择单据类型" clearable>
            <el-option
              v-for="item in typeList"
              :key="item.code"
              :label="item.name"
              :value="item.code"
            />
          </el-select>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="carrierName"
          title="承运商"
          min-width="200"
          sortable
        />
        <template v-slot:header="{ column }">
          <el-select @change="carrierChange" v-model="listQuery.carrierCodeList" clearable filterable multiple collapse-tags placeholder="承运商">
            <el-option
              v-for="item in carrierList"
              :key="item.code"
              :label="item.name"
              :value="item.code">
            </el-option>
          </el-select>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="waybillCode"
          title="运单号"
          min-width="150"
          sortable
        />
        <template v-slot:header="{ column }">
          <el-input
            v-model="listQuery.waybillCode"
            placeholder="运单号"
            clearable
          />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="splitWaybillCode" title="拆分运单号" min-width="150" show-overflow sortable />
        <template #header>
          <el-input v-model="listQuery.splitWaybillCode" placeholder="拆分运单号" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="packageNum" title="包裹数" min-width="200" sortable/>
        <template #header>
          <el-input v-model="listQuery.packageNumStart" placeholder="下限" type='number' style="width:45%;"/>
          -
          <el-input v-model="listQuery.packageNumEnd" placeholder="上限" type='number' style="width:45%;"/>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="goodsSortQuantity"
          title="种数"
          min-width="300"
          sortable
        />
        <template v-slot:header="{ column }">
          <el-input
            v-model="listQuery.goodsSortQuantityStart"
            placeholder="下限"
            clearable
            type='number'
            style="width: 45%"
          />
          -
          <el-input
            v-model="listQuery.goodsSortQuantityEnd"
            placeholder="上限"
            clearable
            type='number'
            style="width: 45%"
          />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="totalNum"
          title="件数"
          min-width="300"
          sortable
        />
         <template v-slot:header="{ column }">
        <el-input
          v-model="listQuery.totalNumStart"
          placeholder="下限"
          clearable
          type='number'
          style="width: 45%"
        />
        -
          <el-input
            v-model="listQuery.totalNumEnd"
            placeholder="上限"
            clearable
            type='number'
            style="width: 45%"
          />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="distributionNum"
          title="分配数量"
          min-width="300"
          sortable
        />
        <template v-slot:header="{ column }">
          <el-input
            v-model="listQuery.distributionNumStart"
            placeholder="下限"
            clearable
            type='number'
            style="width: 45%"
          />
          -
          <el-input
            v-model="listQuery.distributionNumEnd"
            placeholder="上限"
            clearable
            type='number'
            style="width: 45%"
          />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="weight"
          title="重量"
          min-width="300"
          sortable
        />
        <template v-slot:header="{ column }">
          <el-input
            v-model="listQuery.weightStart"
            placeholder="下限"
            clearable
            type='number'
            style="width: 45%"
          />
          -
          <el-input
            v-model="listQuery.weightEnd"
            placeholder="上限"
            clearable
            type='number'
            style="width: 45%"
          />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="volume"
          title="体积"
          min-width="300"
          sortable
        />
        <template v-slot:header="{ column }">
          <el-input
            v-model="listQuery.volumeStart"
            placeholder="下限"
            clearable
            type="number"
            style="width: 45%"
          />
          -
          <el-input
            v-model="listQuery.volumeEnd"
            placeholder="上限"
            clearable
            type="number"
            style="width: 45%"
          />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="money" title="金额" min-width="300" sortable />
        <template v-slot:header="{ column }">
          <el-input
            v-model="listQuery.moneyStart"
            placeholder="下限"
            clearable
            type="number"
            style="width: 45%"
          />
          -
          <el-input
            v-model="listQuery.moneyEnd"
            placeholder="上限"
            clearable
            type="number"
            style="width: 45%"
          />
        </template>
      </vxe-table-column>
       <vxe-table-column>
        <vxe-table-column
          field="receiverName"
          title="收货人"
          min-width="150"
          sortable
        />
        <template v-slot:header="{ column }">
          <el-input
            v-model="listQuery.receiverName"
            placeholder="收货人"
            clearable
          />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="receiverMobile"
          title="收货人电话"
          min-width="150"
          sortable
        />
        <template v-slot:header="{ column }">
          <el-input
            v-model="listQuery.receiverMobile"
            placeholder="收货人电话"
            clearable
          />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="receiverProvince" title="省份" min-width="150" sortable/>
        <template #header>
          <el-input v-model="listQuery.receiverProvince" placeholder="请输入省份" clearable/>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="receiverCity" title="城市" min-width="150" sortable/>
        <template #header>
          <el-input v-model="listQuery.receiverCity" placeholder="请输入城市" clearable/>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="receiverDistrict" title="区县" min-width="150" sortable/>
        <template #header>
          <el-input v-model="listQuery.receiverDistrict" placeholder="请输入区县" clearable/>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="receiverDetailAddress"
          show-overflow
          title="收货人地址"
          min-width="700"
          sortable
        />
        <template v-slot:header="{ column }">
          <el-input
            v-model="listQuery.receiverDetailAddress"
            placeholder="收货人地址"
            clearable
          />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="sourcePlatformName" title="销售平台" min-width="164" sortable/>
        <template #header>
          <el-select v-model="listQuery.sourcePlatformCode" placeholder="请选择销售平台" clearable>
            <el-option v-for="item in salePlatformList" :key="item.sourcePlatformCode" :label="item.sourcePlatformName" :value="item.sourcePlatformCode" />
          </el-select>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="gmtCreated"
          show-header-overflow
          show-overflow
          title="接收时间"
          min-width="400"
          sortable
          :resizable="false"
        />
        <template v-slot:header>
          <el-date-picker
            popper-class="popper-left"
            v-model="gmtCreatedRange"
            type="datetimerange"
            value-format="yyyy-MM-dd HH:mm:ss"
            :picker-options="pickerOptions"
            style="width: 100%"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="(value) => changeDate(value, 'gmtCreated')"
          />
        </template>
      </vxe-table-column>
      <vxe-table-column title="操作" fixed="right" width="60">
        <template slot-scope="scope">
          <el-tooltip  effect="dark" content="查看" placement="top">
            <vxe-button
              type="text"
              @click="modelShowHide(scope.row.code)"
            >
              <i class="el-icon-document" />
            </vxe-button>
          </el-tooltip>
        </template>
      </vxe-table-column>
    </vxe-table>
    <vxe-modal
      v-model="operationModel"
      title="查看"
      width="78%"
      height="650"
      destroy-on-close
    >
      <compEdit
        :operationCode="operationCode"
        @operationComplete="
          modelShowHide();
          findList();
        "
      />
    </vxe-modal>

    <vxe-modal
      v-model="wavePickingModel"
      title="波次确定"
      width="26%"
      min-height="200"
      destroy-on-close
    >
      <wavePickings
        :waveCodeList="waveCodeList"
        :shipmentCodes="shipmentCodes"
        @refresh="handleWavePickingModel();findList()"
      />
    </vxe-modal>
    <vxe-modal
      v-model="changeCarrierModel"
      title="更改承运商"
      min-height="200"
      destroy-on-close
    >
      <changeCarrier
        :visible.sync="changeCarrierModel"
        :changeCarrierData="changeCarrierData"
        @refresh="handleChangeCarrierModel();findList()"
      />
    </vxe-modal>
    <vxe-pager
      :current-page.sync="listQuery.pageNum"
      :page-size.sync="listQuery.pageSize"
      :total="listQuery.total"
      :layouts="[
        'PrevJump',
        'PrevPage',
        'Number',
        'NextPage',
        'NextJump',
        'Sizes',
        'FullJump',
        'Total',
      ]"
      :page-sizes="[10, 15, 20, 50, 100, 500, 1000]"
      @page-change="handlePageChange"
    />
    <vxe-modal v-model="printExpressBillmodel" title="打印运单" width="600" height="600" destroy-on-close>
      <printFaceSheet :printData="printData" titleTemplate="选择标准运单模板" :parcelType="parcelType" @finshPrint="openClosePrintMode" />
    </vxe-modal>
    <vxe-modal v-model="commodityModel" title="商品查询" width="1150" height="500" destroy-on-close resize>
      <goodsInquire @goods="goodsValue" />
    </vxe-modal>
    <vxe-modal v-model="explosiveModel" title="爆品查询" width="950" height="500" destroy-on-close resize>
      <explosive @explosive="explosiveValue" />
    </vxe-modal>
    <!-- cancelWave 取消波次 -->
    <vxe-modal v-model="cancelWaveModel" title="取消波次" width="650" destroy-on-close resize>
      <cancelWave :cancelSelect="cancelSelect" @operationComplete="cancelWaveClick();findList();" />
    </vxe-modal>
  </div>
</template>

<script>
import Vue from 'vue'
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'
import XEUtils from 'xe-utils'
import VXEUtils from 'vxe-utils'
Vue.use(VXETable, VXEUtils, XEUtils, { mounts: ['cookie'] })
import { copyToClipboard } from '@/utils/index'
import printFaceSheet from '@/components/Printing'
import queryCriteria from "./components/queryCriteria.vue";
import compEdit from "./components/orderDetail.vue";
import wavePickings from "./components/wavePickings.vue";
import changeCarrier from "./components/changeCarrier.vue";
import explosive from './components/explosiveInquire.vue'
import goodsInquire from './components/goodsInquire.vue'
import cancelWave from './components/cancelWave.vue'
import { getWarehouse, chooseSourcePlatformList } from '@/api/basicInfo'
import { waveList, getEnumList, batchUpdateWaybill, shipments, carrierDropdown, queryProvinceCitys } from "@/api/outStorage";
import soonPrint from '@/components/Printing/printBefore.js'
export default {
  name: "订单处理",
  components: {
    queryCriteria,
    compEdit,
    wavePickings,
    changeCarrier,
    printFaceSheet,
    explosive,
    goodsInquire,
    cancelWave
  },
  props: {},
  data() {
    return {
      initFinishFlag: false, //生成波次按钮
      printWaybillBtn: true, // 打印运单按钮
      tableData: [],
      // 状态
      statusList: [
        { value: '0', label: '新增' },
        { value: '1', label: '待分配' },
        { value: '2', label: '部分分配' },
        { value: '3', label: '已分配' },
        { value: '6', label: '待拣货' },
        { value: '7', label: '待复核' },
        { value: '8', label: '复核中' },
        { value: '9', label: '待出库' },
        { value: '11', label: '出库完成' },
        { value: '12', label: '拣货中' },
        { value: '13', label: '拣货完成' }
      ],
      orderData:[
        {orderTag:'单品'},
        {orderTag:'多品'},
      ],
      gmtCreatedRange:'',
      sourceList: [],
      warehouseData:[],
      typeList: [
        { code: '0', name: '销售出库' },
         //   { code: '1', name: '报损出库' },
         //   { code: '2', name: '领用出库' },
         //   { code: '3', name: '盘亏出库' },
         //   { code: '4', name: '采购退货' },
         //   { code: '5', name: '调拨出库' },
      ],
      loading: false,
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      checked: false,
      areaInfo: [],
      receiverDistricts: [],
      areaOptions: [],
      listQuery: {
        carrierCode: '',
        carrierCodeList: [],
        code: this.$route.query.code,
        gmtCreated: '',
        status: '3',
        sourceType: '',
        shopNick:'',
        warehouseName: '',
        shipmentName: '',
        wavePickingCode: '',
        isvCode: '',
        sourceCode:'',
        goodsSortQuantityStart:'',
        volumeStart:'',
        volumeEnd:'',
        waybillCode:'',
        type:'',
        carrierName:'',
        total: 0,
        pageNum: 1,
        pageSize: 50,
        goodCodes:'',
        goodsNums:'',
        normalGoodCodes: "",
        sourcePlatformName:'',
        stopAreas: '',
        warehouseCode: this.$store.getters.authorizeDataCode
      },
      modelDetailFlag: false,
      operationModel: false,
      operationCode:'',
      wavePickingModel: false,
      changeCarrierModel: false,
      changeCarrierData: {},
      wavePickingCodes: "",
      maximum: "", //最大
      numberValidateForm: {
        maxNum: "",
      },
      getEnum:{
        type: 'com.arpa.wms.domain.enums.DeliverySourceTypeEnum'
      },
      waveCodeList:[],
      shipmentCodes: [], // 入驻商编码集合
      parcelType: '', // 哪家快递
      printData: [], // 要打印的运单数据
      printExpressBillmodel: false, //打印机组件
      commodityModel: false, //商品查询
      explosiveModel: false, //
      cancelWaveModel: false, // 取消波次
      options: [],
      prepackagedList: [
        { value: '0', label: '否' },
        { value: '1', label: '是' }
      ],
      carrierList: [],
      cancelSelect: [],
      salePlatformList: [], //销售平台下拉框列表数据
      needLoadList: false // 在keep-live钩子函数activated内是否需要加载列表
    };
  },
  created() {
    this.findList();
    this.getWarehouse();
    getEnumList(this.getEnum).then((response) => {
      this.sourceList = response.data
    });
    window.onstorage = ({key}) => {
      if (key.indexOf('printComplete') != -1) {
        this.$message.success('打印任务执行完毕~')
        this.findList()
        this.$refs.xTable.clearCheckboxRow()
        localStorage.removeItem(key)
      }
    }
    queryProvinceCitys().then(res => this.areaOptions = res.data)
    chooseSourcePlatformList().then(res => this.salePlatformList = res.data)
  },
  computed: {
    'printFlag': function() {
      if(this.initFinishFlag) {
        let selectRecords = this.$refs.xTable.getCheckboxRecords();
        if(selectRecords.length > 0) {
          this.disabled = false
          let stateShow = false
          for (let i = 0; i < selectRecords.length; i++) {
            if (selectRecords[i].status != '3') {
              stateShow = true
              break
            }
          }
          return stateShow
        } else {
          this.disabled = true
          return true;
        }
      }
      return true;
    }
  },
  mounted() {},
  activated() {
    const { meta: { noCache } } = this.$route
    if (!noCache && this.needLoadList) this.findList()
  },
  methods: {
    // 商品查询
    commodityClick(){
      this.commodityModel = !this.commodityModel
    },
    goodsValue(value){
      if(value){
        this.commodityModel = !this.commodityModel
        this.listQuery.normalGoodCodes = value
      }
    },
    // 爆品查询
    explosiveClick(){
      this.explosiveModel = !this.explosiveModel
    },
    explosiveValue(value){
      if(value){
        this.explosiveModel = !this.explosiveModel
        this.listQuery.goodCodes = value.groupGoodCode
        this.listQuery.goodsNums = value.groupQuantity
      }
    },
    // 排序
    sortField({ column, property, order }) {
      if (order) {
        this.listQuery.sortField = property;
        this.listQuery.sortType = order;
      } else {
        this.listQuery.sortField = "";
      }
      this.findList();
    },
    // 查询
    findList(good) {
      if(good){
        if((this.listQuery.normalGoodCodes && this.listQuery.goodCodes) || (this.listQuery.normalGoodCodes && this.listQuery.goodsNums)){
          this.$message.error('普通商品和爆品请分开查询');
          return false
        }
        if((this.listQuery.goodCodes && !this.listQuery.goodsNums) || (!this.listQuery.goodCodes && this.listQuery.goodsNums)){
          this.$message.error('爆品商品编码个数与商品数量个数不一致，无法查询');
          return false
        }
      }
      this.loading = true
      this.printWaybillBtn = true
      shipments().then(res => {
        this.options = res.data
      })
      carrierDropdown().then(res => {
        this.carrierList = res.data
      })
      if (this.areaInfo) {
        let receiverCities = [], stopDistricts = []
        this.areaInfo.forEach((item)=>{
          if (item.length === 3) {
            const districts = item[1] +'-'+ item[2]
            stopDistricts.push(districts)
          } else {
            receiverCities.push(item.slice(-1)[0])
          }
        })
        this.listQuery.stopAreas = receiverCities.join(',')
        this.listQuery.stopDistricts = stopDistricts.join(',')
      } else {
        this.listQuery.stopAreas = ''
        this.listQuery.stopDistricts = ''
      }

      if (this.receiverDistricts) {
        let receiverCities = []
        this.receiverDistricts.forEach((item)=>{
          const districts = item[1] +'-'+ item[2]
          receiverCities.push(districts)
        })
        this.listQuery.receiverDistrict = receiverCities.join(',')
      } else {
        this.listQuery.receiverDistrict = ''
      }

      return new Promise(resolve=>{
          waveList(this.listQuery).then(res => {
          if(res.status === 0){
            this.loading = false
            this.tableData = res.data.records
            for (let i = 0; i < this.tableData.length; i++) {
              this.tableData[i].receiverDetailAddress = this.tableData[i].receiverDetailAddress
            }
            this.listQuery.total = res.data.sumObject.total;
            this.initFinishFlag = true;
          }
        }).finally(()=> {
          this.needLoadList = true
        })
        resolve()
      })
    },
    changeDate(value, prefix = 'gmtCreated') {
      if (value) {
        this.listQuery[`${prefix}Start`] = value[0]
        this.listQuery[`${prefix}End`] = value[1]
      } else {
        this.listQuery[`${prefix}Start`] = ''
        this.listQuery[`${prefix}End`] = ''
      }
      if (prefix === 'gmtCreated') {
        this.gmtCreatedRange = value
      }
    },
    // 全选与否、部分勾选与否
    checkboxChangeEvent({selection}) {
      // 已作废的单子不能打印
      this.printWaybillBtn = selection.some(item => item.status === '4')
    },
    // 复制运单号
    copyText({column: { property }, row: { splitWaybillCode }}) {
      if (property === 'splitWaybillCode') {
        copyToClipboard(splitWaybillCode, res => {
          res && this.$XModal.message({ message: '运单号已复制', status: 'success' })
        })
      }
    },
    // 打印运单
    printWaybill(){
      let selectRecords = this.$refs.xTable.getCheckboxRecords()
      let arr = []
      if(selectRecords.length === 0){
        this.$message.error("请选择要打印运单的数据!");
        return
      }
      let expressType = []
      let oddNumbers = [];
      let arrs = []
      selectRecords.forEach((i) => {
        if ((i.carrierName == '') || (i.waybillCode == '')) {
          arr.push(i.code);
        } else {
          let v = `单号${i.code}`
          let s = i.code
          oddNumbers.push(v)
          arrs.push(s)
          expressType.push(i.carrierName);
        }
      });
      if (oddNumbers.length < 1) {
        this.$message.error('请选择带有承运商和运单号的单据来进行打印 ')
        return false
      }
      if (expressType.length>0) {
        let arr = [...new Set(expressType)]
        if (arr.length>1) {
          this.$message.error('批量打印同时只能打印同一家快递！')
          return false
        }
      }
        localStorage.setItem('printCode', JSON.stringify(arrs))
        let routeUrl = this.$router.resolve({
          path: '/printResult',
          query: {
            type: 'array',
            listInterface: 'printExpress'
          }
        })
        soonPrint(routeUrl.href)
        // window.open(routeUrl.href, '_blank')
    },
    // 更新面单信息
    updateWaybill() {
      let arr = []
      let selectRecords = this.$refs.xTable.getCheckboxRecords()
      if(selectRecords.length === 0){
        this.$message.error("请选择要更新面单的数据!");
        return
      }
      selectRecords.forEach((i) => {
        if (i.code && i.code !== '') {
          arr.push(i.code);
        }
      });
      const rLoading = this.openLoading('更新中...')
      batchUpdateWaybill(arr).then(res => {
        this.$refs.xTable.clearCheckboxRow() //清除所有行选中
        rLoading.close() // 关闭遮罩层
        this.$message.success(res.msg)
      })
    },
    openClosePrintMode() {
      this.printExpressBillmodel = !this.printExpressBillmodel
    },
    printTest() {
      let printData = {"cmd":"print","requestID":"123458666","version":"1.0","task":{"taskID":"729666666","preview":true,"printer":"","notifyMode":"allInOne","previewType":"pdf","documents":[{"documentID":"012345678555","contents":[{"data":{"recipient":{"address":{"city":"杭州市","detail":"良睦路999号乐佳国际大厦2号楼小邮局","district":"余杭区","province":"浙江省","town":""},"mobile":"13012345678","name":"菜鸟网络","phone":"057112345678"},"routingInfo":{"routeCode":"123A-456-789"},"sender":{"address":{"city":"杭州市","detail":"文一西路1001号阿里巴巴淘宝城5号小邮局","district":"余杭区","province":"浙江省","town":""},"mobile":"13012345678","name":"阿里巴巴","phone":"057112345678"},"waybillCode":"0123456999"},"templateURL":"http://cloudprint.cainiao.com/template/standard/290659/44"},{"templateURL":"http://cloudprint.cainiao.com/template/customArea/13450842/4"}]}]}}
      if (!this.socket) {
        this.socket = new socketClient({
          url: 'ws://localhost:13528',
          received: function(data) {
            // 监听服务器返回信息
            // console.log('received--->', data)
          }
        })
      }
      this.socket.sendCommand(printData)
    },
    reset() {
        this.listQuery.gmtCreated = ''
        this.listQuery.status = '3'
        this.listQuery.sourceType = ''
        this.listQuery.shopNick = ''
        this.listQuery.warehouseName = ''
        this.listQuery.shipmentName = ''
        this.listQuery.wavePickingCode = ''
        this.listQuery.isvCode = ''
        this.listQuery.deliveryOrderCode =''
        this.listQuery.waybillCode =''
        this.listQuery.type = ''
        this.listQuery.carrierName = ''
        this.listQuery.total = 0
        this.listQuery.pageNum = 1
        this.listQuery.goodCodes = ''
        this.listQuery.goodsNums = ''
    },
    // 多选
    includeChange(val) {
      if(val)
      this.listQuery.containGoods=1;
      else
          this.listQuery.containGoods=0;
    },
    // 波次单选
    maximumChange(val) {
      if (val === false) {
        this.$refs.examine.maxNum("barCode");
      } else {
      }
    },
    // 分页handle
    handlePageChange({ currentPage, pageSize }) {
      this.listQuery.pageNum = currentPage;
      this.listQuery.pageSize = pageSize;
      this.findList();
    },
    // 查看
    modelShowHide(code) {
      this.operationModel = !this.operationModel;
      if (code) {
        this.operationCode = code;
      }
    },
    //仓库查询
    getWarehouse(){
      getWarehouse().then(response => {
        this.warehouseData = response.data
        this.warehouseCode = this.warehouseData[0].code
        this.initFinishFlag = true;
      })
    },
    // 生成波次弹窗
    handleWavePickingModel() {
      this.wavePickingModel = !this.wavePickingModel
    },
    // 波次
    waveShowHide() {
      let selectRecords = this.$refs.xTable.getCheckboxRecords()
      let arr = []
      let shipmentCodes = []
      selectRecords.forEach((i) => {
        if (i.code && i.code !== '') {
          arr.push(i.code);
          if (!shipmentCodes.includes(i.shipmentCode)) {
            shipmentCodes.push(i.shipmentCode)
          }
        }
      });
      this.shipmentCodes = shipmentCodes
      this.waveCodeList = arr
      this.handleWavePickingModel()
    },
    // 取消波次
    cancelWaveClick() {
      let selectRecords = this.$refs.xTable.getCheckboxRecords()
      if(selectRecords.length === 0 || selectRecords.length > 1) {
        this.$message.warning('请选择一条数据进行波次取消！')
      } else {
        if(selectRecords[0].status === '6') {
          this.cancelWaveModel = !this.cancelWaveModel
          this.cancelSelect = selectRecords
        } else {
          this.$message.warning('请选择状态为待拣货的数据进行波次取消！')
        }
      }
    },
    // 处理 更换承运商 弹窗
    handleChangeCarrierModel() {
      this.changeCarrierModel = !this.changeCarrierModel
    },
    // 更换承运商
    changeCarrier() {
      const selectRecords = this.$refs.xTable.getCheckboxRecords()
      const shipmentCode = selectRecords[0].shipmentCode
      if (selectRecords.every((item) => item.shipmentCode === shipmentCode)) {
        this.changeCarrierData = {
          shipmentCode,
          carrierCode: selectRecords[0].carrierCode,
          deliveryCodes: selectRecords.map(item => item.code)
        }
        this.handleChangeCarrierModel()
      } else {
        this.$message.warning('选择的入驻商必须相同！')
      }
    },
    // 翻译是否预打包状态
    formatterPackaged({cellValue}) {
      if (cellValue == '0') {
        return '否'
      }
      if (cellValue == '1') {
        return '是'
      }
    },
    //
    formatterSource({ cellValue }){
      if (cellValue == 'wms') {
          return '手工创建'
        }
        if (cellValue == 'oms') {
          return 'OMS'
        }
        if (cellValue == 'qimen') {
          return '奇门'
        }
        if (cellValue == 'other') {
          return '其他'
        }
    },
    // 单据类型
    formatterType({ cellValue }){
        if (cellValue == '0') {
          return '销售出库'
        }
        if (cellValue == '1') {
          return '破损出库'
        }
        if (cellValue == '2') {
          return '领用出库'
        }
        if (cellValue == '3') {
          return '盈亏出库'
        }
        if (cellValue == '4') {
          return '采购退货'
        }
        if (cellValue == '5') {
          return '调拨出库'
        }
    },
    // 承运商多选
    carrierChange(data) {
      if (data) {
        this.listQuery.carrierCode = data.join(',')
      } else {
        this.listQuery.carrierCode = ''
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.container {
  margin: 16px;
}
.inputWidth {
  width: 300px;
}
/* .mytable-footer{
  margin-top: 30px;
} */
/deep/ .vxe-table--render-default .vxe-cell {
  white-space: revert;
}
.btnMarginTop{
  margin-bottom: 10px;
}
.ml20{
  margin-left: 20px;
}
.popper-left {
  ::v-deep .el-popper {
    left: -30px !important;
  }
}

</style>
